﻿// Copyright 2001-2010 - Active Up SPRLU (http://www.agilecomponents.com)
//
// Data Connection Suite is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.

// Data Connection Suite is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
// for more details.

// You should have received a copy of the GNU General Public License along with
// Data Connection Suite. If not, see http://www.gnu.org/licenses/.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Common;

namespace AgileComponents.DataConnection
{
    /// <summary>
    /// 
    /// </summary>
    public partial class ConnectionStringPropertiesDialog : Form
    {
        private string _connectionString;

        /// <summary>
        /// Initializes a new instance of the <see cref="ConnectionStringPropertiesDialog"/> class.
        /// </summary>
        /// <param name="builder">The builder.</param>
        public ConnectionStringPropertiesDialog(DbConnectionStringBuilder builder)
        {
            InitializeComponent();

            _builder = builder;
            _connectionString = builder.ToString();
            this.connectionBuilderPropertyGrid.SelectedObject = builder;
            this.connectionStringTextBox.Text = _builder.ToString();
        }

        private DbConnectionStringBuilder _builder;
        /// <summary>
        /// Gets the builder.
        /// </summary>
        /// <value>The builder.</value>
        public DbConnectionStringBuilder Builder
        {
            get
            {
                return _builder;
            }
        }

        /// <summary>
        /// Handles the PropertyValueChanged event of the connectionBuilderPropertyGrid control.
        /// </summary>
        /// <param name="s">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.PropertyValueChangedEventArgs"/> instance containing the event data.</param>
        private void connectionBuilderPropertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            this.connectionStringTextBox.Text = _builder.ToString();
        }

        /// <summary>
        /// Handles the Click event of the okButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void okButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the cancelButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Builder.ConnectionString = _connectionString;
            this.Close();
        }
    }
}
